from rest_framework import serializers
from teacher.serializers import TeacherBriefSerl
from persons.serializers import PersonBriefSerl
from student.models import StudentInvite
from student.models import StudentInvitePerson
from student.models import StudentInviteVerify
from student.models import StudentModel
from student.models import StudentPerson


class StudentSerl(serializers.ModelSerializer):
    updated = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S")

    class Meta:
        model = StudentModel
        exclude = ("created",)


class StudentBriefSerl(serializers.ModelSerializer):

    class Meta:
        model = StudentModel
        fields = (
            "id",
            "dept",
            "name",
            "phone",
        )


class StudentPersonSerl(serializers.ModelSerializer):
    student = StudentBriefSerl()
    person = PersonBriefSerl()

    class Meta:
        model = StudentPerson
        fields = ("id", "student", "person")


class StudentInviteDetSerl(serializers.ModelSerializer):
    student = StudentBriefSerl()
    person = PersonBriefSerl()
    STATUS_CHOISE = (
        (0, "教师审核中"),
        (1, "保卫处审核中"),
        (5, "审核完成"),
        (6, "审核失败"),
        (7, "访问中"),
        (8, "完成访问"),
        (9, "访问过期"),
        (10, "取消"),
    )
    status_text = serializers.ChoiceField(
        choices=STATUS_CHOISE, source="get_status_display"
    )
    when = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S")
    updated = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S")

    class Meta:
        model = StudentInvite
        exclude = ("created",)


class StudentInviteLstSerl(serializers.ModelSerializer):
    person = PersonBriefSerl()
    student = StudentBriefSerl()
    STATUS_CHOISE = (
        (0, "教师审核中"),
        (1, "保卫处审核中"),
        (5, "审核完成"),
        (6, "审核失败"),
        (7, "访问中"),
        (8, "完成访问"),
        (9, "访问过期"),
        (10, "取消"),
    )
    status_text = serializers.ChoiceField(
        choices=STATUS_CHOISE, source="get_status_display"
    )
    when = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S")

    class Meta:
        model = StudentInvite
        fields = ("id", "person", "student", "status", "status_text", "when")


class StudentInvitePersonSerl(serializers.ModelSerializer):
    invite = StudentInviteLstSerl()
    person = PersonBriefSerl()

    class Meta:
        model = StudentInvitePerson
        fields = ("id", "invite", "person")


class StudentInviteVerifySerl(serializers.ModelSerializer):
    updated = serializers.DateTimeField(format="%Y-%m-%d %H:%M:%S")
    teacher = TeacherBriefSerl()
    STATGE_CHOISE = (
        (0, "教师审核中"),
        (1, "保卫处审核中"),
        (5, "审核完成"),
        (6, "审核失败"),
        (7, "访问中"),
        (8, "完成访问"),
        (9, "访问过期"),
        (10, "取消"),
    )
    stage_text = serializers.ChoiceField(
        choices=STATGE_CHOISE, source="get_stage_display"
    )
    STATUS_CHOISE = (
        (0, "待审核"),
        (1, "审核通过"),
        (2, "审核失败"),
    )
    status_text = serializers.ChoiceField(
        choices=STATUS_CHOISE, source="get_status_display"
    )

    class Meta:
        model = StudentInviteVerify
        exclude = ("created",)
